package com.example.zbh.lessona.getcolor;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.graphics.Palette;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zbh.lessona.R;

/**
 * Created by nanchaodong on 15/12/31.
 */
public class GetColorActivity extends Activity {
    private ImageView imageView;
    private TextView textView;
    private Bitmap bitmap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_color);
        init();
    }

    private void init() {
        imageView = (ImageView) findViewById(R.id.imageView);
        textView = (TextView) findViewById(R.id.textView);
        bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.abc);
        imageView.setImageBitmap(bitmap);
        Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() {
            @Override
            public void onGenerated(Palette palette) {
//                Palette.Swatch swatch = palette.getVibrantSwatch();有活力的
//                Palette.Swatch swatch = palette.getDarkVibrantSwatch();有活力的暗色
//                Palette.Swatch swatch = palette.getLightVibrantSwatch();有活力的亮色
//                Palette.Swatch swatch = palette.getDarkMutedSwatch(); 柔和的暗色
//                Palette.Swatch swatch = palette.getLightMutedSwatch();柔和的亮色
                Palette.Swatch swatch = palette.getMutedSwatch();//柔和的
                if (swatch != null){
                    textView.setTextColor(swatch.getRgb());
                }

            }
        });


    }
}
